www.gusucode.com > 光谱读入、降噪和去背景一体化matlab 源码 > 光谱读入、降噪和去背景一体化matlab 源码/wavelet_denoise_deback_pw.m
clear;clc; dir='D:\m\';%%%%%%%%%% 输入文件所在目录 %%%%%%%%%% read the signal of background. fname='background-15mw-500um-10s.txt';%输入文件名 filename=strcat(dir,fname);%%%%%%%%%% 构成文件路径 fid=fopen(filename,'r'); num=fscanf(fid,'%f %f',[2,inf]); fclose(fid); bg_y=num(2,:);bg_x=num(1,:); %backgroud后的信号 subplot(4,1,1);plot(bg_x,bg_y,'b');grid;;%画出原始信号波形,同时画四个 title('backgroud signal'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% fname='glu-15mw-500um-10s-2.txt';%the filename of nacl filename=strcat(dir,fname); fid=fopen(filename,'r'); num=fscanf(fid,'%f %f',[2,inf]); fclose(fid); NL_y=num(2,:);NL_x=num(1,:); %nacl信号 %NL_y=num(2,:)-mean(num(2,3110:3189));NL_x=num(1,:); %去直流分量的nacl信号 subplot(4,1,2);plot(NL_x,NL_y,'r');grid;;%画出nacl原始信号波形 title('glue signal'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%% use wavelet to realize the filter. dn=wden(bg_y,'sqtwolog','s','sln',5,'sym8');% sqtlog,sln 组合滤波毛刺最少最光滑 %wden have several threshold selection rules:'rigrsure' uses the principle %of Stein's Unbiased Risk . 'heursure' is an heuristic variant of the first option. % 'sqtwolog' for universal threshold 'minimaxi'for minimax thresholding % sym8 is one kind of wavelets.'s' is the soft,(the other is hard) thresholding. subplot(4,1,3);plot(NL_x,dn,'g'); title('de-noised signal');grid; %%%%% remove the backgound signal y=NL_y-dn; subplot(4,1,4);plot(NL_x,y,'k');;title('remove backgroup');grid; %%%%%%%画出原始信号波形 title('glue signal removes the bacground'); newfilename=strcat(dir,'de_background_',fname);%输出文件为:de_backgroud_ + 原文件名 fid=fopen(newfilename,'wt'); count=fprintf(fid, '%4.2f %3.4f\n', cat(1,NL_x,y)); %%输出滤波后信号到文件 fclose(fid);